// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
 * @file AlarmInfo_tCdrAux.ipp
 * This source file contains some declarations of CDR related functions.
 *
 * This file was generated by the tool fastddsgen.
 */

#ifndef _FAST_DDS_GENERATED_ALARMINFO_TCDRAUX_IPP_
#define _FAST_DDS_GENERATED_ALARMINFO_TCDRAUX_IPP_

#include "AlarmInfo_tCdrAux.hpp"

#include <fastcdr/Cdr.h>
#include <fastcdr/CdrSizeCalculator.hpp>


#include <fastcdr/exceptions/BadParamException.h>
using namespace eprosima::fastcdr::exception;

namespace eprosima {
namespace fastcdr {



template<>
eProsima_user_DllExport size_t calculate_serialized_size(
        eprosima::fastcdr::CdrSizeCalculator& calculator,
        const AlarmInfo_t& data,
        size_t& current_alignment)
{
    static_cast<void>(data);

    eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding();
    size_t calculated_size {calculator.begin_calculate_type_serialized_size(
                                eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ?
                                eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
                                eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
                                current_alignment)};


        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0),
                data.m_PEDESTRIAN_INVASION_CLEARANCES_ALARM_INFO(), current_alignment);

        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1),
                data.m_TRAIN_INVASION_CLEARANCES_ALARM_INFO(), current_alignment);

        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(2),
                data.m_OTHER_OBSTACLE_INVASION_CLEARANCES_ALARM_INFO(), current_alignment);

        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(3),
                data.m_INTRUSION_OBJECT_DISTANCE_CALCULATE_FAILED_ALARM_INFO(), current_alignment);

        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(4),
                data.m_INTRUSION_OBJECT_VELOCITY_CALCULATE_FAILED_ALARM_INFO(), current_alignment);

        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(5),
                data.m_CLEARANCES_AREA_LENGTH_TOO_SHORT_ALARM_INFO(), current_alignment);

        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(6),
                data.m_CLEARANCES_AREA_RECOGNITION_FAILED_ALARM_INFO(), current_alignment);

        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(7),
                data.m_LIDAR_SENSOR_FAULT_ALARM_INFO(), current_alignment);

        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(8),
                data.m_LONG_FOCUS_CAMERA_SENSOR_FAULT_ALARM_INFO(), current_alignment);

        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(9),
                data.m_SHORT_FOCUS_CAMERA_SENSOR_FAULT_ALARM_INFO(), current_alignment);

        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(10),
                data.m_MILLIMETERM_WAVE_RADAR_SENSOR_FAULT_ALARM_INFO(), current_alignment);

        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(11),
                data.m_ATP_COMMUNICATION_TIMEOUT_ALARM_INFO(), current_alignment);

        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(12),
                data.m_TRAIN_INTERFACE_COMMUNICATION_TIMEOUT_ALARM_INFO(), current_alignment);

        calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(13),
                data.m_RESERVE(), current_alignment);


    calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);

    return calculated_size;
}

template<>
eProsima_user_DllExport void serialize(
        eprosima::fastcdr::Cdr& scdr,
        const AlarmInfo_t& data)
{
    eprosima::fastcdr::Cdr::state current_state(scdr);
    scdr.begin_serialize_type(current_state,
            eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ?
            eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
            eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);

    scdr
        << eprosima::fastcdr::MemberId(0) << data.m_PEDESTRIAN_INVASION_CLEARANCES_ALARM_INFO()
        << eprosima::fastcdr::MemberId(1) << data.m_TRAIN_INVASION_CLEARANCES_ALARM_INFO()
        << eprosima::fastcdr::MemberId(2) << data.m_OTHER_OBSTACLE_INVASION_CLEARANCES_ALARM_INFO()
        << eprosima::fastcdr::MemberId(3) << data.m_INTRUSION_OBJECT_DISTANCE_CALCULATE_FAILED_ALARM_INFO()
        << eprosima::fastcdr::MemberId(4) << data.m_INTRUSION_OBJECT_VELOCITY_CALCULATE_FAILED_ALARM_INFO()
        << eprosima::fastcdr::MemberId(5) << data.m_CLEARANCES_AREA_LENGTH_TOO_SHORT_ALARM_INFO()
        << eprosima::fastcdr::MemberId(6) << data.m_CLEARANCES_AREA_RECOGNITION_FAILED_ALARM_INFO()
        << eprosima::fastcdr::MemberId(7) << data.m_LIDAR_SENSOR_FAULT_ALARM_INFO()
        << eprosima::fastcdr::MemberId(8) << data.m_LONG_FOCUS_CAMERA_SENSOR_FAULT_ALARM_INFO()
        << eprosima::fastcdr::MemberId(9) << data.m_SHORT_FOCUS_CAMERA_SENSOR_FAULT_ALARM_INFO()
        << eprosima::fastcdr::MemberId(10) << data.m_MILLIMETERM_WAVE_RADAR_SENSOR_FAULT_ALARM_INFO()
        << eprosima::fastcdr::MemberId(11) << data.m_ATP_COMMUNICATION_TIMEOUT_ALARM_INFO()
        << eprosima::fastcdr::MemberId(12) << data.m_TRAIN_INTERFACE_COMMUNICATION_TIMEOUT_ALARM_INFO()
        << eprosima::fastcdr::MemberId(13) << data.m_RESERVE()
;
    scdr.end_serialize_type(current_state);
}

template<>
eProsima_user_DllExport void deserialize(
        eprosima::fastcdr::Cdr& cdr,
        AlarmInfo_t& data)
{
    cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ?
            eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
            eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
            [&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool
            {
                bool ret_value = true;
                switch (mid.id)
                {
                                        case 0:
                                                dcdr >> data.m_PEDESTRIAN_INVASION_CLEARANCES_ALARM_INFO();
                                            break;

                                        case 1:
                                                dcdr >> data.m_TRAIN_INVASION_CLEARANCES_ALARM_INFO();
                                            break;

                                        case 2:
                                                dcdr >> data.m_OTHER_OBSTACLE_INVASION_CLEARANCES_ALARM_INFO();
                                            break;

                                        case 3:
                                                dcdr >> data.m_INTRUSION_OBJECT_DISTANCE_CALCULATE_FAILED_ALARM_INFO();
                                            break;

                                        case 4:
                                                dcdr >> data.m_INTRUSION_OBJECT_VELOCITY_CALCULATE_FAILED_ALARM_INFO();
                                            break;

                                        case 5:
                                                dcdr >> data.m_CLEARANCES_AREA_LENGTH_TOO_SHORT_ALARM_INFO();
                                            break;

                                        case 6:
                                                dcdr >> data.m_CLEARANCES_AREA_RECOGNITION_FAILED_ALARM_INFO();
                                            break;

                                        case 7:
                                                dcdr >> data.m_LIDAR_SENSOR_FAULT_ALARM_INFO();
                                            break;

                                        case 8:
                                                dcdr >> data.m_LONG_FOCUS_CAMERA_SENSOR_FAULT_ALARM_INFO();
                                            break;

                                        case 9:
                                                dcdr >> data.m_SHORT_FOCUS_CAMERA_SENSOR_FAULT_ALARM_INFO();
                                            break;

                                        case 10:
                                                dcdr >> data.m_MILLIMETERM_WAVE_RADAR_SENSOR_FAULT_ALARM_INFO();
                                            break;

                                        case 11:
                                                dcdr >> data.m_ATP_COMMUNICATION_TIMEOUT_ALARM_INFO();
                                            break;

                                        case 12:
                                                dcdr >> data.m_TRAIN_INTERFACE_COMMUNICATION_TIMEOUT_ALARM_INFO();
                                            break;

                                        case 13:
                                                dcdr >> data.m_RESERVE();
                                            break;

                    default:
                        ret_value = false;
                        break;
                }
                return ret_value;
            });
}

void serialize_key(
        eprosima::fastcdr::Cdr& scdr,
        const AlarmInfo_t& data)
{
    static_cast<void>(scdr);
    static_cast<void>(data);
}



} // namespace fastcdr
} // namespace eprosima

#endif // _FAST_DDS_GENERATED_ALARMINFO_TCDRAUX_IPP_

